/*
	This file implements basic operation of stack, list, queue
*/

#include <iostream>
using namespace std;

int *A = new int[10];
int stack_top = 0;	// record the position of top of stack

struct node		// Used in list
{
	node *prev;
	node *next;
	int val;
};

// Stack
bool stack_empty(int *S)
{
	if(stack_top == 0)
		return true;
	else
		return false;
}

void stack_push(int *S, int val)
{
	stack_top ++;
	S[stack_top] = val;
}

void stack_pop(int *S)
{
	if(stack_top==0)
		cout << "error" << endl;
	else
		stack_top--;
}

// Queue: insert from the tail and delete from the head. 
int head = 0;
int tail = 0; // always point to the empty position for next element.
int queue_len = 0;

bool queue_empty(int *Q)
{
	if(head==tail)	// Yes, empty
		return true;
	else return false;
}

bool queme_full(int *Q)
{
	if(head == tail+1)	// Yes, full
		return true;
	else return false;
}

void Equeue(int *Q, int val)  // Add from left to right
{
	Q[tail] = val;
	if(tail<queue_len)
		tail++;
	else
		tail = 0;
}

void Dqueue(int *Q)	      // Delete from left to right
{
	if(head==queue_len)
		head=0;
	else
		head++;
}

// List: double list, 

node *list_head;

node *list_search(node *list, int key)
{
	node *tmp = list_head;
	while((tmp!=NULL) && (tmp->val !=key))
	{
		if(tmp->val==key)
			return tmp;
		else tmp=tmp->next;
	}
	return NULL;
}

void list_insert(node *list, node *new_node)
{
	new_node->next = list_head;
	if(list_head!= NULL)	// Not an empty list
	{
		(list_head)->prev = new_node;
	}
	list_head = new_node;
	list_head->prev = NULL;
}

void list_delete(node *list, node *delete_node)
{	// Delete_node is the node supposed to be deleted
	if(delete_node->next != NULL)
	{
		(delete_node->next)->prev = delete_node->prev;	
	}
	if(delete_node->prev != NULL) // not delete the first of list
	{
		(delete_node->prev)->next = delete_node->next;
	}
	else
		list_head = delete_node->next;
}

int main()
{
	return 0;
	int i;
	for(i=1;i<10;i++)
		A[i] = 0;
}
